/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myftp.app.plugin;

import myftp.app.view.listener.CreditsActionListener;
import java.awt.Dimension;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;
import myftp.app.view.*;
import myftp.app.view.adapter.TemplateAdapter;
import myftp.app.view.listener.ExitActionListener;
import myftp.app.view.listener.OpenServerActionListener;
import myftp.core.Template;
import myftp.core.controller.plugin.PluginAbstract;
import myftp.core.view.MultiSplitView;

/**
 *
 * @author CAVARLE Glenn, LUCAS Stéphane
 * plugin d'initialisation du Template
 * (toute la partie interface graphique)
 * lancé par le front
 */
public class TemplatePlugin extends PluginAbstract {

    /**
     * initialisation du template
     * avec la mainView de type multisplit
     * initialisation des viewPart
     */
    public void init() {
        Template layout = Template.getInstance();

        layout.setName("MyFTP");
        layout.setSize(1000, 800);
        layout.setDefaultCloseOperation(Template.DO_NOTHING_ON_CLOSE);
        layout.addWindowListener(new TemplateAdapter());
        layout.setLocationRelativeTo(null);
        layout.setJMenuBar(this.buildMenu());

        MultiSplitView mainView = new MultiSplitView();
        mainView.toolbar = new ConnectBarPartView().init();
        mainView.top = new PromptPartView().init();
        mainView.center = new JTabbedPane();
        mainView.bottom = new TransfertView().init();

        mainView.top.setPreferredSize(new Dimension(layout.getWidth(), 200));
        mainView.center.setPreferredSize(new Dimension(layout.getWidth(), 300));
        mainView.bottom.setPreferredSize(new Dimension(layout.getWidth(), 100));

        layout.setViewPart("connectBar", mainView.toolbar);
        layout.setViewPart("prompt", mainView.top);
        layout.setViewPart("tabContainer", mainView.center);
        layout.setViewPart("transfertView", mainView.bottom);
        layout.setMainView(mainView);
        layout.startup();

        layout.invalidate();

    }

    /**
     * création du menu
     * @return JMenuBar
     */
    private JMenuBar buildMenu() {
        JMenuBar menuBar = new JMenuBar();
        JMenu file = new JMenu("Fichier");
        JMenuItem exit = new JMenuItem("Exit");
        exit.addActionListener(new ExitActionListener());

        JMenuItem open = new JMenuItem("Serveurs");
        open.addActionListener(new OpenServerActionListener());

        JMenu aPropos = new JMenu("?");
        JMenuItem credits = new JMenuItem("Crédits");
        credits.addActionListener(new CreditsActionListener());

        file.add(open);
        file.add(exit);

        aPropos.add(credits);

        menuBar.add(file);
        menuBar.add(aPropos);

        return menuBar;

    }
}
